<!DOCTYPE html>
<html>
<head>
   <title>CSS Animations - restarting animation</title>
   <link rel="author" title="Opera Software ASA" href="http://www.opera.com/">
   <link rel="help" href="http://dev.w3.org/csswg/css3-animations/#animations">
   <meta name="flags" content="dom">
   <meta name="assert" content="In order to restart an animation,
   'animation-name' must be removed then reapplied">
   <script src="/resources/testharness.js"></script>
   <script src="/resources/testharnessreport.js"></script>
   <style type="text/css">
      @keyframes slide {
         from {
            left: 0px;
         }
         to {
            left: 100px;
         }
      }
      div {
         width: 100px;
         height: 100px;
         background: blue;
         position: relative;
      }
      .test {
         animation: slide 1s forwards;
      }
   </style>
   <script type="text/javascript">
      setup({explicit_done:true});
      onload = function() {
         var testName = document.querySelector('title').firstChild.data;
         var div = document.querySelector('div');
         var log = document.querySelectorAll('p')[1].firstChild;
         var beforeStop, afterStop, afterRestart;
         var restartOK = false;
         var passed = false;
         function aboutEqual(observed, actual) {
            var maxDeviation = 0.1;
            return (Math.abs(observed - actual) < maxDeviation);
         }
         function report() {
            clearTimeout(timeout);
            test(function(){assert_true(passed);}, testName);
            done();
            log.data = passed ? 'PASS if the animation occurred.' : 'FAIL';
         }
         var timeout = setTimeout(report, 2000);
         div.addEventListener('animationend', function(evt) {
            passed = restartOK && aboutEqual(evt.elapsedTime, 1);
         });
         div.addEventListener('animationstart', function() {
            if (afterStop) {
               afterRestart = getComputedStyle(div, null).left;
               restartOK = beforeStop != 'auto' && afterStop == 'auto'
                           && afterRestart != 'auto'
                           && parseFloat(afterRestart) < parseFloat(beforeStop);
            }
         });
         setTimeout(function() {
            var divStyle = getComputedStyle(div, null);
            beforeStop = divStyle.left;
            div.className = '';
            afterStop = divStyle.left;
            div.className = 'test';
         }, 500);
         div.className = 'test';
      }
   </script>
   <style>iframe{display:none}</style>
</head>
<body>
   <p>The square below should start sliding right, then jump back to the
   beginning and slide right again for 1 second.</p>
   <p>Testing...</p>
   <div></div>
</body>
</html>
